package com.muyaxuan.mail.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.muyaxuan.mail.common.PageModel;
import com.muyaxuan.mail.dao.UserDao;
import com.muyaxuan.mail.dto.User;

//admin/user/userList
/**
 * 用户管理类
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/admin/user")
public class UserController {
	PageModel pageModel = new PageModel();
	
	UserDao userDao=null;
	/**
	 * 用户列表
	 * @param userId
	 * @param pageIndex
	 * @param data
	 * @return
	 */
	@RequestMapping("/userList")
	public String showUserList(String userId,@RequestParam(name="pageIndex",defaultValue="0")int pageIndex,
			Model data){
		
		userDao = new UserDao();
		
		Map<String,Object> params = new HashMap<>();
		//设置总的数据
		pageModel.setRecordCount(userDao.count(userId));
		//设置当前页码
		pageModel.setPageIndex(pageIndex);
		//将userid放入集合
		params.put("userId", userId);
		//将分页模型放入集合
		params.put("pageModel", pageModel);
		//查询操作
		List<User> userList = userDao.getUserByPage(params);
		//将查到的集合放入requset请求中
		data.addAttribute("userList",userList);
		//将分页模型放入requset请求中
		data.addAttribute("pageModel", pageModel);
        //跳转用户列表页面
		return "user/userList";
	}
	/**
	 * 跳转用户更新页面
	 * @param id 用户id
	 * @param data
	 * @return
	 */
	@RequestMapping("/showUpdate")
	public String showUpdate(int id,Model data){
		userDao = new UserDao();
		
		User user = userDao.getUserById(id);
		
		data.addAttribute("user",user);
		
		return "user/update";
	}
	
	
	
	

}
